Page({
    data: {
        total_price: 0,
        price: 0,
        cash_price: 0,
        total_cash: 0,
        team_count: 0,
        order_money: 0,
        hidden: true,
        no_send:0,
        no_peisong:0,
        no_offline:0
    },
    onLoad: function(t) {
      getApp().page.onLoad(this,t);
      console.log(this.data.__user_info); 
      var user_info = this.data.__user_info;
      if (user_info.is_clerk == 0) {
        wx.redirectTo({
          url: '/offline/tz-apply/tz-apply',
        });
        return;
      }
      getApp().core.setNavigationBarColor({
        frontColor: '#ffffff',
        backgroundColor: '#ff4a40'
      })
    },
    onReady: function() {},
    onShow: function() {
        getApp().page.onShow(this);
        var t = this, a = wx.getStorageSync("share_setting"), o = t.data.__user_info;
        t.setData({
            share_setting: a
        }), o && 0 != o.is_clerk ? t.checkUser() : t.loadData();
    },
    checkUser: function() {
        var a = this;
        getApp().core.showLoading({
            title: "正在加载",
            mask: !0
        }), getApp().request({
            url: getApp().api.commander.get_info,
            success: function(t) {
                var __user_info={
                    shop_id:0,
                };
                if (!t.data.shop_info){
                  wx.redirectTo({
                    url: '/offline/tz-apply/tz-apply',
                  })
                }
                0 == t.code && (a.setData({
                    total_price: t.data.price.total_price,
                    price: t.data.price.price,
                    terday_price: t.data.price.terday_price,
                    today_price: t.data.price.today_price,
                    cash_price: t.data.price.cash_price,
                    total_cash: t.data.price.total_cash,
                    team_count: t.data.team_count,
                    order_money: t.data.order_money,
                    custom: t.data.custom,
                    shop_info: t.data.shop_info,
                    order_money_un: t.data.order_money_un,
                    deputy_info: t.data.deputy_info,
                    no_send: t.data.no_send,
                    no_peisong: t.data.no_peisong,
                    no_offline: t.data.no_offline,
                }), getApp().core.setStorageSync("custom", t.data.custom), a.loadData()), 1 == t.code && (__user_info.shop_id = t.data.shop_id,

                a.setData({
                    __user_info: __user_info
                  }), getApp().core.setStorageSync("user_info", __user_info));

            },
            complete: function() {
                getApp().core.hideLoading();
            }
        });
    },
    loadData: function() {
        var a = this;
        getApp().core.showLoading({
            title: "正在加载",
            mask: !0
        }), getApp().request({
            url: getApp().api.commander.index,
            success: function(t) {
                if (0 == t.code) {
                    if (t.data.share_setting) e = t.data.share_setting; else var e = t.data;
                    getApp().core.setStorageSync("share_setting", e), a.setData({
                        share_setting: e
                    });
                }
            },
            complete: function() {
              getApp().core.hideLoading();
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    apply: function(a) {
        var o = wx.getStorageSync("share_setting"), i = wx.getStorageSync("user_info");
        1 == o.share_condition ? wx.navigateTo({
            url: "/pages/add-share/index"
        }) : 0 != o.share_condition && 2 != o.share_condition || (0 == i.shop_id ? wx.showModal({
            title: "申请成为团长",
            content: "是否申请？",
            success: function(n) {
                n.confirm && (wx.showLoading({
                    title: "正在加载",
                    mask: !0
                }), e.request({
                    url: t.commander.join,
                    method: "POST",
                    data: {
                        form_id: a.detail.formId
                    },
                    success: function(t) {
                        0 == t.code && (0 == o.share_condition ? (i.is_distributor = 2, wx.navigateTo({
                            url: "/pages/add-share/index"
                        })) : (i.is_distributor = 1, wx.redirectTo({
                            url: "/user/share/index"
                        })), wx.setStorageSync("user_info", i));
                    },
                    complete: function() {
                        wx.hideLoading();
                    }
                }));
            }
        }) : wx.navigateTo({
            url: "/pages/add-share/index"
        }));
    },
    saoma: function () {
        wx.scanCode({
            success(res) {
                wx.navigateTo({
                    url: '../../' + res.path

                })
            }
        })
    },
    modal_saoma:function(){
      this.setData({
        hidden: !this.data.hidden
      })
    },
  cancel: function () {
    this.setData({
      hidden: true
    });
  },

    updatePasong:function (){
      var o = this;
      wx.showModal({
        title: "提示",
        content: "是否改变配送状态",
        cancelText: "否",
        confirmText: "是",
        success: function (s) {
          if (s.cancel) return !0;
          s.confirm && (wx.showLoading({
            title: "操作中"
          }), e.request({
            url: t.commander.up_peisong,
            data: {
              shop_id: o.data.shop_info.id
            },
            success: function (t) {
              wx.hideLoading();

                  if(t.code==1){
                      wx.showModal({
                          title: "提示",
                          content: t.msg,
                          showCancel: !1,
                          success: function (t) {

                          }
                      });
                  }else{
                      o.setData({
                          'shop_info':t.shop_info
                      })
                  }


            }
          }));
        }
      });
    },
  delDeputy: function (ee) {
    var id = ee.currentTarget.dataset['id'];
    var name = ee.currentTarget.dataset['name'];
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否删除副团长',
      success: function (res) {
        if (res.confirm) {
          e.request({
            url: t.default.del_deputy,
            data: { 'id': id },
            success: function (t) {
              if (0 == t.code) {
                that.setData({
                  deputy_info:''
                })
              } else {
                wx.showToast({
                  icon: "none",
                  title: t.data
                });
              }
            },
          });
        }
      }
    })
  },
});